package com.huawei.tree.binary_tree;

//二叉树案例——前中后序遍历
public class BinaryTreeTest {
    public static void main(String[] args) {
        //创建一个二叉树
        //                                      1:亚索
        //                  2：诺手                                  3：盲僧
        //         4：瑞文            5：腕豪               6：剑圣               7：螳螂
        //    8:狗头    9：武器   10：凯南   11：纳尔     12：豹女  13：千珏    14：凯影    15：小丑
        BinaryTree binaryTree = new BinaryTree();
        //创建需要的节点
        HeroNode node1 = new HeroNode(1,"亚索");
        HeroNode node2 = new HeroNode(2,"诺手");
        HeroNode node3 = new HeroNode(3,"盲僧");
        HeroNode node4 = new HeroNode(4,"瑞文");
        HeroNode node5 = new HeroNode(5,"腕豪");
        HeroNode node6 = new HeroNode(6,"剑圣");
        HeroNode node7 = new HeroNode(7,"螳螂");
        HeroNode node8 = new HeroNode(8,"狗头");
        HeroNode node9 = new HeroNode(9,"武器");
        HeroNode node10 = new HeroNode(10,"凯南");
        HeroNode node11 = new HeroNode(11,"纳尔");
        HeroNode node12 = new HeroNode(12,"豹女");
        HeroNode node13 = new HeroNode(13,"千珏");
        HeroNode node14 = new HeroNode(14,"凯影");
        HeroNode node15 = new HeroNode(15,"小丑");


        //手动创建二叉树，后边学习递归创建二叉树
        binaryTree.setRoot(node1);
        node1.setLeft(node2);
        node2.setLeft(node4);
        node2.setRight(node5);
        node1.setRight(node3);
        node3.setLeft(node6);
        node3.setRight(node7);
        node4.setLeft(node8);
        node4.setRight(node9);
        node5.setLeft(node10);
        node5.setRight(node11);
        node6.setLeft(node12);
        node6.setRight(node13);
        node7.setLeft(node14);
        node7.setRight(node15);

        //前序遍历
        System.out.println("前序遍历");
        binaryTree.preOrder();
        System.out.println("##########");

        //中序遍历
        System.out.println("中序遍历");
        binaryTree.midOrder();
        System.out.println("##########");

        //后序遍历
        System.out.println("后序遍历");
        binaryTree.afterOrder();
        System.out.println("##########");

        //前序遍历查找
        System.out.println("前序遍历查找：3、10");
        System.out.println(binaryTree.preOrderSearch(3));
        System.out.println(binaryTree.preOrderSearch(10));
        System.out.println("##########");

        //中序遍历查找
        System.out.println("中序遍历查找：5、10");
        System.out.println(binaryTree.midOrderSearch(5));
        System.out.println(binaryTree.midOrderSearch(10));
        System.out.println("##########");

        //后序遍历查找
        System.out.println("后序遍历查找：7、10");
        System.out.println(binaryTree.afterOrderSearch(7));
        System.out.println(binaryTree.afterOrderSearch(10));
        System.out.println("##########");

        //删除子节点(规定1)
        binaryTree.delNode1(0);
        binaryTree.delNode1(5);
        //binaryTree.delNode1(1);
        System.out.println("删除5节点（规定1）后前序遍历");
        binaryTree.preOrder();
        System.out.println("##########");

        //删除子节点（规定2）
        binaryTree.delNode2(3);
        System.out.println("删除3节点（规定2）后前序遍历");
        binaryTree.preOrder();
        System.out.println("##########");

        //删除子节点（规定2）
        binaryTree.delNode2(1);
        System.out.println("删除1节点（规定2）后前序遍历");
        binaryTree.preOrder();
        System.out.println("##########");
    }

}
